<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .home {
            height: 510px;
            width: 900px;
            box-shadow: 0 0 8px black;
            position: relative;
             overflow: hidden; 
            margin: 100px auto;
            cursor: pointer;
        }

        .home ol {
            width: 2700px;
            transform: translateX(0);
            transition: 0.2s linear;
        }

        .home ol li {
            float: left;
        }

        .home ul {
            position: absolute;
            bottom: 0;
            left: 350px;
            margin-bottom: 20px;
        }

        .home ul li {
            width: 36px;
            height: 20px;
            border-radius: 5px;
            background-color: black;
            float: left;
            margin-left: 20px;
            opacity: 0.5;
        }

        .home ul li:hover {
            background-color: #768895;
        }

        .btnL {
            border: none;
            width: 70px;
            height: 160px;
            position: absolute;
            bottom: 200px;
            left: 0;
            background-color: black;
            opacity: 0.5;
            color: #fff;
            display: none;
            z-index: 99;
            font-size: 30px;
        }

        .btnR {
            border: none;
            width: 70px;
            height: 160px;
            position: absolute;
            bottom: 200px;
            right: 0;
            background-color: black;
            opacity: 0.5;
            color: #fff;
            display: none;
            z-index: 99;
            font-size: 30px;
        }

        .btnL:hover {
            background-image: linear-gradient(-90deg, #fff, transparent);
        }

        .btnR:hover {
            background-image: linear-gradient(-90deg, #fff, transparent);
        }
    </style>
</head>

<body>
    <div class="home">
        <button class="btnL"><</button>
        <button class="btnR">></button>
        <ol>
            <li><img src="./img/t1.png" alt=""></li>
            <li><img src="./img/t2.png" alt=""></li>
            <li><img src="./img/t3.png" alt=""></li>
        </ol>

        <ul>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <script>
        var btnL = document.querySelector('.btnL');
        var btnR = document.querySelector('.btnR');
        var home = document.querySelector('.home');
        var ol = document.querySelector('.home').querySelector('ol');
        var lis = document.querySelector('.home').querySelector('ul').querySelectorAll('li');

        // 鼠标移动时  左右两个按钮显示

        home.addEventListener('mouseover', function () {
            btnL.style.display = 'block';
            btnR.style.display = 'block';
            clearTimeout(time);
        })
        home.addEventListener('mouseleave', function () {
            btnL.style.display = 'none';
            btnR.style.display = 'none';
            time = setInterval(timer, 2000);
        })


        // 点击下面仨点  跳转相应位置

        for (let i = 0; i < lis.length; i++) {
            lis[i].onclick = function () {
                var x = 900 * i;
                ol.style.transform = `translateX(${-x}px)`
            }
        }


        var j = 0; // 声明一个计数器
        btnR.addEventListener('click', function () {
            j++;
            if (j > 2) j = 0;
            ol.style.transform = `translateX(${-900 * j}px)`;
        })
        btnL.addEventListener('click', function () {
            j--;
            if (j < 0) j = 2;
            ol.style.transform = `translateX(${-900 * j}px)`;
        })


        var time = setInterval(timer, 3500); // 创建一个计时器 间隔2s  调用timer函数
        function timer() {
            console.log(j);
            j++;
            if (j > 2) {
                j = 0
            };
            ol.style.transform = `translateX(${-900 * j}px)`;
            for (let k = 0; k < lis.length; k++) { // 排他思想
                lis[k].style.backgroundColor = "black"
            }
            lis[j].style.backgroundColor = '#A1B5C3'
        }
        for (let k = 0; k < lis.length; k++) {
            lis[k].addEventListener('mouseover', function () {

                this.style.backgroundColor = '#768895';
                this.style.backgroundColor = '#768895';
            })
            lis[k].addEventListener('mouseleave', function () {
                this.style.backgroundColor = 'black';
                this.style.backgroundColor = 'black';
            })
        }

    </script>

    </div>
    <script>

    </script>
</body>

</html>